<?php

class Admin_Form_SectorSearch extends Zend_Dojo_Form
{
    public function init()
    {    	
        $this->setName("SectorSearch");
        $this->setMethod('post');
        $this->addAttribs(array('onSubmit'=>'return validate(this)'));
        
		$this->addElement('TextBox', 'name',array(
	        'label'          => 'Nome: ',
         	'focus'          => true,
	        'invalidMessage' => 'Nome inválido',
        	'style'      	 => 'width: 400px;',
		));

		$this->addElement('TextBox', 'acronym',array(
	        'label'          => 'Sigla: ',
         	'focus'          => true,
			'maxlength'		 => 20,
	        'regExp'         => '[\w]+',
	        'invalidMessage' => 'Sigla inválida',
        	'style'      	 => 'width: 250px;',
		));

    	//Organs
		$ogansDbTable = new Admin_Model_Organs();
		$organs = $ogansDbTable->getOrgans();
		$organOptions[null] = '';
		foreach($organs as $key => $val) {
			$organOptions[$val['name']] =  $val['name'];
		}

		$this->addElement('ComboBox','id_organ',array(
			'label'        => 'Orgão: ',
			'value'        => 'id_organ',
			'style'        => 'width: 400px;',
			'required'     => false,
			'autocomplete' => true,
			'multiOptions' => $organOptions
		));

		//Sectors
		$sectorDbTable = new Admin_Model_Sectors();
		$sectors = $sectorDbTable->getSectors();
		$sectorOptions[null] = '';
		foreach($sectors as $key => $val) {
			$organsDbTable = new Admin_Model_Organs();
			$organ = $organsDbTable->getOrganById($val['id_organ']);
			$sectorOptions[$val['id']] = $organ['acronym'].'-'.$val['name'];
		}
		
		$this->addElement('ComboBox','id_sector',array(
			'label'        => 'Setor Vinculado: ',
			'value'        => 'id_sector',
			'style'        => 'width: 400px;',
			'required'     => false,
			'autocomplete' => true,
			'multiOptions' => $sectorOptions
		));
		
        $this->addElement('SubmitButton', 'button', array(
            'label'    => 'Pesquisar',
	        'required' => false,
	        'ignore' => true,
        ));  
        
        $this->addDisplayGroup(array('name','acronym','id_organ','id_sector','button'), 'search', array('legend'=>"Pesquisar")); 

    }
}

